package com.example.internet;


import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import java.util.List;

public class MainActivity extends AppCompatActivity implements View.OnClickListener{
    ListView listView;
    List<Computet> list;
    TextView tvAdd;
    TextView tvClose;
    Intent intent;
    MyBaseAdapter adapter;
    SqlUse use;

    @Override
    protected void onRestart() {
        super.onRestart();
        use = new SqlUse(MainActivity.this);
        list = use.findAll();
        adapter = new MyBaseAdapter(MainActivity.this,list);
        listView.setAdapter(adapter);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        initData();
    }
    private void initView(){
        listView = findViewById(R.id.recr_note);
        tvAdd = findViewById(R.id.tv_add);
        tvClose = findViewById(R.id.tv_close);
        tvAdd.setOnClickListener(this);
        tvClose.setOnClickListener(this);
        intent = new Intent();
    }

    private void initData(){
        use = new SqlUse(MainActivity.this);
        list = use.findAll();
        adapter= new MyBaseAdapter(MainActivity.this,list);
        listView.setAdapter(adapter);

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.tv_add:
                intent.putExtra("type","添加");
                intent.setClass(MainActivity.this,ActivityAdd.class);
                startActivity(intent);
                break;

            case R.id.tv_close:
               finish();
        }
    }
}